<?php
error_reporting(E_ERROR | E_WARNING | E_PARSE);
function isrand(){
	return mt_rand(0, 9999);
}
function save_img($filename) {
	global $arr_save;
	$path=substr($filename, 0, (strrpos($filename, "/")+1));
	$file_name=substr($filename, (strrpos($filename, "/")+1));
	$file=substr($file_name, 0,strrpos($file_name, "."));
	$ext=substr($filename, strrpos($filename, "."));
	$num=strlen($file);
	$sum1=mt_rand(0, $num-1);
	$a=$file{$sum1};
	$new_file=str_replace($a, $a."l", $file);
	$new_fn=$path.$new_file.$ext;
	rename($filename, $new_fn);
	$arr_save[]=$filename."-->".$new_fn;
//	echo $filename."-->".$new_fn;
//	echo "--".$num."---".$a.$b."----".$new_fn;
//	echo "--".$path."--".$file."-0-".$ext;
//	echo "<br>";
}
function getdir($path) {
	$arr = scandir($path);
	foreach ($arr as $v) {
		if ($v != "." && $v != "..") {
			if (is_dir($path . "/" . $v)) {
				getdir($path . "/" . $v);
			} else {
				$ext = substr($v, (strrpos($v, ".") + 1));
				if ($ext == 'jpg' || $ext == 'png' ) {
					if(isrand() == 1){
						save_img($path . "/" . $v);
					}
				}
			}
		}
	}
}
getdir("..");
if($arr_save){
	echo count($arr_save);
	require_once("../data/common.inc.php");
	$char="utf8";
	$link=mysqli_connect('127.0.0.1', $cfg_dbuser, $cfg_dbpwd);
	mysqli_select_db($link,$cfg_dbname);
	mysqli_set_charset($link,$char);
	foreach($arr_save as $v){
		$sql_tab="insert into wzwa_saveimg (save) values ('".$v."');";
		$re_tab=mysqli_query($link,$sql_tab);
	}
}else{
	echo "arr_save is null";
}
?>